<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use app\admin\service\ApiService;
use think\Db;
//use app\wechat\controller\Common;

class IndexController extends HomeBaseController
{
    public function index()
    {
    	$userid = cmf_get_current_user_id();
        $part = Db::name('wechat_department_user')
        ->alias('a')
        ->join('member b','a.user_id=b.openid')
        ->where('b.id',$userid)
        ->column('a.department_id');

        $user = Db::name('member')
        ->alias('a')
        ->join('cmf_wechat_tag_user b','a.openid=b.userid')
        ->where('a.id',$userid)
        ->column('b.tagid');

    	if (in_array(config('meet_admin'), $user)) {
            $user_type = 3;
        }elseif(in_array(config('meet'), $user)){
            $user_type = 2;
        }elseif(in_array(config('fix'), $user)){
            $user_type = 4;
        }elseif (in_array(config('meet_vip'), $user)) {
            $user_type = 5;
        }else{
            $user_type = 1;
        }
        $this->assign('user_type',$user_type);//1:普通用户 2:会务员查看 3: 会议管理员
        /*if ($user_type == 4 ) {
            $this->redirect('repair/List/myRepair');
        }*/
        $where = ['a.department_id'=>['in',0,$part]];

        $info = Db::name('new_msg')
        ->alias('a')
        ->join('new_msg_user b','a.id=b.msg_id','LEFT')
        ->join('wechat_department c','a.department_id=c.id','LEFT')
        ->field('a.*,b.id as isset,c.name')
        ->where($where)
        ->order('time desc')
        ->select();
        /*$work = Db::name('new_msg')
        ->alias('a')
        ->join('new_msg_user b','a.id=b.msg_id')
        ->where(['a.type'=>2])
        ->count();
        print_r($work);

        $notice = Db::name('new_msg')
        ->alias('a')
        ->join('new_msg_user b','a.id=b.msg_id')
        ->where(['a.type'=>1])
        ->count();
        print_r($notice);

        $repair = Db::name('new_msg')
        ->alias('a')
        ->join('new_msg_user b','a.id=b.msg_id')
        ->where(['a.type'=>3,'a.user_id'=>$userid])
        ->count();
        print_r($repair);*/
        $this->assign('msg',$info);
        return $this->fetch(':index');
    }
    public function test(){
        $common = new \app\wechat\controller\Common();
    	$ticket = $common->getSignPackage();
        print_r($ticket);
    }
}
